export const requestSubscribeMessage = {
	onReady() {
	},
	methods: {
		data() {
			return {
			}
		},
		RSMessage(data) {
			const that = this
			uni.requestSubscribeMessage({
				tmplIds: data,//模板id
				success(res) {
					//'accept'表示用户同意订阅该条id对应的模板消息
					if (res[data[0]] == "accept") { 
						// 字段就是tmplIds模板id
						uni.getSetting({
							withSubscriptions: true,
							success(res) {
								console.log(66,res)
								// let send = res.subscriptionsSetting.itemSettings?res.subscriptionsSetting.itemSettings[data[0]]:''
								that.dingyue()
							}
						})
					} else {
						uni.showToast({
							icon: 'error',
							title: '取消订阅',
						})
					}
				}
			})
		},
		// 订阅
		dingyue(item) {
			let typeList = [
				'case', 
				'share', 
				'lecture', 
				"liveBack", 
				'class', 
				'jifen', 
				'buyClassSuccess', 
				'Journa',
				'buyVIP',
				'siginSuccess', 
				'siginRemind'
			]
			
			let typeNum = typeList.indexOf(this.pageType) + 1
			
			let quaryData = {
				type: typeNum,
				status: 1,
			}
			
			this.$u.api.subscribe(quaryData).then(res => {
				if (res.code == 1) {
					uni.showToast({
						title: '订阅成功',
					})
				}
			})
			
			if (typeNum == 7) {
				quaryData.type = 6
				let res1 = this.$u.api.subscribe(quaryData)
			} else if (typeNum == 10) {
				quaryData.type = 11
				let res1 = this.$u.api.subscribe(quaryData)
			} else if (typeNum == 9) {
				quaryData.type = 12
				let res1 = this.$u.api.subscribe(quaryData)
			}
		},
		
		// queding 第一步
		async messageConfirm() {
			let res = await this.getStatus()
			this.RSMessage(res)
		},
		
		// 获取状态
		getMessageStatus() {
			let typeList = [
				'case', 
				'share', 
				'lecture', 
				"liveBack", 
				'class', 
				'jifen', 
				'buyClassSuccess', 
				'Journa',
				'buyVIP',
				'siginSuccess', 
				'siginRemind'
			]
			let typeNum = typeList.indexOf(this.pageType) + 1
			let quaryData = {
				type: typeNum
			}
			this.$u.api.messageStatu(quaryData).then(res => {
				if (res.data) {
					this.messageShow = true
				}else{
					this.messageShow = false
				}
			})
		},
		// 模板id
		async getStatus() {
			let typeList = [
				'case', 
				'share', 
				'lecture', 
				"liveBack", 
				'class', 
				'jifen', 
				'buyClassSuccess',
				'Journa', 
				'buyVIP', 
				'siginSuccess',
				'siginRemind'
			]
			
			let typeNum = typeList.indexOf(this.pageType) + 1
			
			let quaryData = {
				type: typeNum
			}
			
			let templateid = []
			
			let res = await this.$u.api.message(quaryData)
			
			templateid.push(res.data.templateid)
			
			if (typeNum == 7) {
				let res1 = await this.$u.api.message({
					type: 6
				})
				templateid.push(res1.data.templateid)
			} else if (typeNum == 10) {
				let res1 = await this.$u.api.message({
					type: 11
				})
				templateid.push(res1.data.templateid)
			} else if (typeNum == 9) {
				let res1 = await this.$u.api.message({
					type: 12
				})
				templateid.push(res1.data.templateid)
			}
			
			return templateid
		}

	}
}
